import type { UserConfig, ConfigEnv } from 'vite'
import { resolve } from 'path'
import vue from '@vitejs/plugin-vue'
import styleImport from 'vite-plugin-style-import'

// https://vitejs.dev/config/
export default ({ command, mode }: ConfigEnv): UserConfig => {
  return {
    // base: process.env.VITE_BASE_URL,
    // base: '/vue3-store-admin',
    resolve: {
      alias: [
        {
          find: '@',
          replacement: resolve(__dirname, './src'),
        },
      ],
    },
    plugins: [
      vue(),
      styleImport({
        libs: [
          {
            libraryName: 'ant-design-vue',
            esModule: true,
            resolveStyle: (name) => {
              return `ant-design-vue/es/${name}/style/index`
            },
          },
        ],
      }),
    ],
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: `@import "@/styles/_variables.scss", "@/styles/_mixins.scss";`,
        },
        less: {
          modifyVars: {},
          javascriptEnabled: true,
        },
      },
    },
    server: {
      port: 9527,
      proxy: {
        '/api': {
          target: 'http://139.198.172.231:8490/',
          changeOrigin: true,
          // rewrite: (path) => path.replace(/^\/api/, '/api/'),
        },
      },
    },
  }
}

// export default defineConfig({
//   resolve: {
//     alias: {
//       '@': path.resolve(__dirname, 'src'),
//     },
//   },
//   plugins: [vue()]
// })
